<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title><{:C('web_site_name')}>---用户管理</title>
    <link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/main.css"/>

    <script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/jquery.js"></script>
    <script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/lib.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/layer.min.js"></script>
</head>
<body>
<div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i>首页<span class="crumb-step">&gt;</span><span class="crumb-name">用户管理</span></div>
        </div>
        <div class="search-wrap">
            <div class="search-content">
                <form action="<?php echo U("member/export");?>" method="post" id="myform" target="_blank">
                <input type="hidden" name="show_field" value="<?php echo $cache_field ; ?>">
                <input type="hidden" name="page" value="1">
                    <table class="search-tab">
                        <tr>
                          	<th width="70">用户编号:</th>
                          	 <td><input class="common-text" type="text" value="" name="uid" placeholder="用户编号">
                           	 </td>
                            <th width="70">用户名:</th>
                            <td>
                              <input id="" class="common-text" type="text" value="" name="username" placeholder="用户名">  
                             <select name="condition"  id="condition">
						        <option value="">请选择</option>
						        <option value="1">模糊查询%%</option>
						        <option value="2">精确查询</option>
						      </select>
                            </td>
                            <th width="70">手机号码:</th>
                             <td>
                         
                       		  <input id="" class="common-text" type="text" value="" name="phone" placeholder="手机号码">
                     		</td>
                            <th width="70">昵称:</th>
                     <td>
                         
                         <input id="" class="common-text" type="text" value="" name="uname" placeholder="昵称">
                     </td>
                     </tr>
                     </table>
                     <table class="search-tab">
                     <tr>
                      <th width="70">性别:</th>
                                <td>
                             <select name="sex">
                                <option value="all">请选择</option>
                                <option value="1">男</option>
                                <option value="2">女</option>  
                            </select>
                                </td>
                                <th width="70">状态:</th>
                                <td>
                             <select name="status">
                                <option value="all">请选择</option>
                                <option value="1">开启</option>
                                <option value="0">关闭</option>  
                            </select>
                                </td>
                                <th width="70">按照:</th>
                                <td>
                             <select name="field">
                                <option value="a.uid">用户的id</option>
                                <option value="a.regdate">注册日期</option> 
                                <option value="a.score">积分</option>  
                                <option value="a.money">钱</option>  
                                <option value="a.sign_days">连续签到的天数</option>  
                            </select>
                                </td>
                                <th width="40">排序:</th>
                                <td>
                             <select name="orderby">
                                <option value="desc">降序</option>
                                <option value="asc">升序</option>  
                            </select>
                                </td>
                            <th width="60">每一页:</th>
                                <td>
                             <select name="pageSize">
                                <?php 
                                    foreach(C("admin_page_size") as $pageSize => $value ){
                                ?> 
                                <option value="<?php echo $pageSize;?>"><?php echo $value;?></option>  
                            <?php } ?>
                            </select>
                                </td>
                            <td><input class="btn btn-primary btn2" name="sub" value="查询" type="button" onclick="search()">
 <input class="btn btn-primary btn2" name="sub" value="自定义查询字段" type="button" onclick="self_field()">
                            </td>
                            <td>
 <input class="btn btn-primary btn2" name="sub" value="根据条件导出数据" type="submit" >
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
               
                 <div class="list-page" id="page_string"> 2 条 1/1 页</div>
                <div class="result-content">
                    <table class="result-tab" width="100%" >
                        <thead id="head">
   						</thead>
                      <tbody id="result_"></tbody>
                        
                    </table>
                    
                        
                    <div class="list-page" id="page_string"> 2 条 1/1 页</div>
                </div>
            </form>
        </div>
</body>
</html>
<div class="field_div" style="border:1px solid #ccc; background-color:#eee;display:none">
  <?php if(isset($all_field) && $all_field ){
        foreach($all_field  as $kkk => $vvv ){
    ?>
  <li style="width:140px ; border:solid 1px green ; float:left ; padding:15px ;margin-right:8px ; margin-top:4px; margin-left:4px;list-style:none"><?php echo $vvv ;?>:
    <input type="checkbox" name="<?php echo $kkk ;?>" value="<?php echo $kkk ;?>" <?php if(@in_array($kkk , $cache_field_array)) {echo "checked";}?>>
  </li>
  <?php }}?>
  <div style="clear:both ; margin-left:40%">
    <input type="button" class="btn btn-primary btn2" value="确定" onclick="get_click_field()">
  </div>
</div>



<script>
var loadding_0  ;
var page = 1 ;
var show_field='<?php echo $cache_field ; ?>';
$(function () {
    common_request();
});
function common_request(){
	$("input[name='page']").val(page);
    var url="<?php echo U("member/index");?>&inajax=1";
    var data_ = {
    		'page':page,
    		'time':<?php echo time();?>,
    		'action':'ajax_data' , 
    		'username':$("input[name='username']").val() , 
    		'phone':$("input[name='phone']").val() ,  
            'uname':$("input[name='uname']").val() , 
    		'condition':$("#condition").val() , 
    		'show_field':show_field	,
    		'status':$("#status").val(),
    		'sex':$("select[name='sex']").val() ,
    		'status':$("select[name='status']").val(),
            'field':$("select[name='field']").val() ,
            'orderby':$("select[name='orderby']").val()  ,
            'uid':$("input[name='uid']").val(),
            'pageSize':$("select[name='pageSize']").val()  
            
    } ;
    //console.dir(data_);
    $.ajax({
    type: "POST",
    url: url ,
    data: data_,
    cache:false,
    dataType:"json",
    // async:false,
    success: function(msg){
    	var shtml = '' ;
		var list = msg.resultinfo.list.list;
		var myhead = msg.resultinfo.list.head ;
		var head = '<tr>';
		
		if(msg.resultcode!=1){
			layer.msg(msg.resultinfo.errmsg);
			return false ;
		}else{
			for(var head_index in myhead){
				head+='<th>'+myhead[head_index]+'</th>';
			}
			head+='</tr>';
			for(var i in list){
				shtml+='<tr id="tr_'+list[i].id+'">';
				//循环列
				for(var colspan in list[i]){
					shtml+= '<td>'+list[i][colspan]+'</td>' ;	
				}
				shtml+='</tr>';
			}
 	 		$("#head").html(head);
			$("#result_").html(shtml);
			$(".list-page").html(msg.resultinfo.obj);
		}
		layer.close(loadding_0);
    },
    beforeSend:function(){
         loadding_0 = layer.load('数据正在加载中。。。。。。'); 
    },
    error:function(){
        layer.msg('服务器繁忙请稍后');
        return false ;
    }
    });
}
function ajax_data(p){
    page = p  ; 
    common_request();
}
function search(){
    page = 1 ;
    common_request();
}

var _edit = '' ;

function edit(id , o ){
    _edit = $.layer({
        type: 2,
        shadeClose: true,
        title: "修改用户信息",
        closeBtn: [0, true],
        shade: [0.8, '#000'],
        border: [1],
        offset: ['20px',''],
        area: ['60%','600px'],
        fix:false,
        iframe: {src: "<?php echo U("member/edit");?>&showpage=1&id="+id}
    }); 
}

//关闭窗口
function close_edit_div(){
    layer.close(_edit);
}
var self_field_0;
//自定义字段
function self_field(){
self_field_0 = $.layer({
    shadeClose: true,
    type: 1,
    shade: [0.8, '#000'],
    area: ['800px', 'auto'],
    title: "自定义字段展示",
    border: [1],
    page: {dom : '.field_div'}
});
}
//获取点击的字段
function get_click_field(){
    var v = '' ;
    $(".field_div li input").each(function(){
        var o = $(this) ;
        if($(this).is(':checked')){
            v+=$(this).val()+',';
        }
    });
    v = v.substring(0 , v.length - 1 );
    if(v == '' ){
        layer.msg("请选择字段进行展示");
        return false ; 
    }
    show_field = v ; 
    $("input[name='show_field']").val(v);
    layer.close(self_field_0);
    //写入缓存里面
    write_cache(show_field);
    common_request() ; //请求数据
}
function write_cache(show_field){
    $.ajax({
        type: "POST",
        url: "<?php echo U("member/index",array('inajax'=>1 , 'action'=>'setField') )?>" ,
        data: {show_field:show_field},
        cache:false,
        dataType:"json",
        async:false,
        success: function(msg){
            layer.close(loadding_0);
        },
        beforeSend:function(){
             loadding_0 = layer.load('正在设置字段。。。。。。'); 
        },
        error:function(){
            layer.msg('服务器繁忙请稍后');
            return false ;
        }
        });
}
</script> 

